#!/usr/bin/env coffee

import chalk from 'chalk'
import {HOME,FS} from '../const/dir.coffee'
import Database from 'better-sqlite3'
import {join} from 'path'
import {mkdirSync,existsSync,readFileSync} from 'fs'

DB_PATH = join(HOME,'db')

is_new = not existsSync DB_PATH

if is_new
  mkdirSync(HOME, { recursive: true })

DB = new Database(
  DB_PATH
  {
    verbose: (sql)=>
      console.log chalk.gray sql
  }
)

#DB.pragma('journal_mode = WAL')

if is_new
  DB.exec readFileSync(join(FS,'db.sql'),'utf8')

export default DB
